package sajat.onlab;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class FriendListAdapter extends BaseAdapter{
	
	private ArrayList<User> users;

	public FriendListAdapter(ArrayList<User> users){
		this.users = users;
	}
	
	@Override
	public int getCount() {
		return users.size();
	}

	@Override
	public Object getItem(int arg0) {
		return users.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		final User user = users.get(position);
		
		if(convertView == null){
			LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.rowlayout, null);
		}
		
		TextView username = (TextView) convertView.findViewById(R.id.username);
		TextView lastseen = (TextView) convertView.findViewById(R.id.lastseen);
		
		username.setText(user.getName());
		lastseen.setText("Last seen: "+user.getLastSeen("yyyy.MM.dd. HH:mm:ss"));
		
		return convertView;
	}

}
